package com.aifast.common.fieldEncrypt;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

/**
 * @Author fujian
 * @since 2022/9/12 10:54
 */
public class FieldsProvider {

    private static final Map<Class<?>, Set<Field>> encryptedFieldCache = new ConcurrentHashMap<>();
    public static Set<Field> get(Class<?> parameterClass) {
        return encryptedFieldCache.computeIfAbsent(parameterClass, clazz -> {
            Field[] declaredFields = clazz.getDeclaredFields();
            return Arrays.stream(declaredFields).filter(field ->
                    field.isAnnotationPresent(FieldEncrypt.class) && field.getType() == String.class)
                    .collect(Collectors.toSet());
        });
    }

}
